package com.alpha.eceasy.mall.controller;

import com.alpha.eceasy.extension.BaseFormInfo;
import com.alpha.eceasy.mall.api.dto.MallDemandDTO;
import com.alpha.eceasy.mall.api.entity.MallDemand;
import com.alpha.eceasy.core.R;
import com.alpha.eceasy.mall.api.vo.MallDemandVO;
import com.alpha.eceasy.mall.service.MallDemandService;
import com.alpha.eceasy.mall.service.impl.MallDemandServiceImpl;
import com.alpha.eceasy.mall.util.SecurityUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 需求联系单
 *
 * @author huangpengfei
 * @since 2022-02-11 16:55:59
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/demand")
@Tag(description = "demand", name = "需求联系单")
public class MallDemandController {
    private final MallDemandServiceImpl mallDemandService;

    /**
     * 分页查询
     *
     * @param dto 需求联系单
     * @return 分页结果
     */
    @GetMapping("")
    @Operation(description = "分页查询", summary = "分页查询")
    public R<IPage<MallDemandVO>> getPageVO(@RequestParam("pageNum") Integer pageNum,
                                            @RequestParam("pageSize") Integer pageSize,
                                            MallDemandDTO dto) {
        return R.ok(mallDemandService.getPageVO(Page.of(pageNum, pageSize), dto));
    }

    /**
     * 通过guid查询需求联系单
     *
     * @param guid guid
     * @return R 返回结果 需求联系单
     */
    @Operation(description = "通过guid查询需求联系单", summary = "通过guid查询需求联系单")
    @GetMapping("/{guid}")
    public R<MallDemand> getByGuid(@PathVariable("guid") String guid) {
        return R.ok(mallDemandService.getByGuid(guid));
    }

    /**
     * 新增需求联系单
     *
     * @param dto 需求联系单
     * @return R 返回结果 是否成功
     */
    //@SysLog("新增需求联系单")
    @Operation(description = "新增需求联系单", summary = "新增需求联系单")
    @PostMapping
    public R<Boolean> save(@RequestBody MallDemandDTO dto) {
        return R.ok(mallDemandService.saveDTO(dto));
    }

    /**
     * 通过guid删除需求联系单
     *
     * @param guid guid
     * @return R 返回结果
     */
    //@SysLog("通过id删除商品")
    @Operation(description = "通过guid删除需求联系单", summary = "通过guid删除需求联系单")
    @DeleteMapping("/{guid}")
    public R<Boolean> removeById(@PathVariable String guid) {
        return R.ok(mallDemandService.removeByGuid(guid));
    }

    /**
     * 修改需求联系单
     *
     * @param entity 需求联系单
     * @return R 返回结果 是否成功
     */
    //@SysLog("修改需求联系单")
    @Operation(description = "通过guid修改需求联系单", summary = "通过guid修改需求联系单")
    @PutMapping
    public R<Boolean> updateById(@RequestBody MallDemand entity) {
        return R.ok(mallDemandService.updateByGuid(entity));
    }

}
